import Vue from "vue";
import Vuex from "vuex";
import token from "../utils/token";

Vue.use(Vuex);
const state = {
  _token: token.getCookie("_token"),
  app_id: token.getCookie("app_id"),
  group_id: token.getCookie("group_id"),
  root_id: token.getCookie("root_id"),
  qiniu: token.getCookie("qiniu"),
  imgRotate: "?imageMogr2/auto-orient",
  app_name: token.getCookie("app_name"),
  app_cover: token.getCookie("app_cover"),
  group_name: token.getCookie("group_name"),
  wx_appid: "",
  draglist: [],
  isshow: false,
  imgInitPgae: 1,
  spellGroupIndex: 0,
  limitIndex: 0,
  bargainIndex: 0
};
const getters = {
  draglist: state => state.draglist
};
const mutations = {
  _token(state, n) {
    state._token = n;
    token.setCookie("_token", n);
    if (!n) token.delCookie("_token");
  },
  app_id(state, n) {
    state.app_id = n;
    token.setCookie("app_id", n);
    if (!n) token.delCookie("app_id");
  },
  app_name(state, n) {
    state.app_name = n;
    token.setCookie("app_name", n);
    if (!n) token.delCookie("app_name");
  },
  app_cover(state, n) {
    state.app_cover = n;
    token.setCookie("app_cover", n);
    if (!n) token.delCookie("app_cover");
  },
  group_name(state, n) {
    state.group_name = n;
    token.setCookie("group_name", n);
    if (!n) token.delCookie("group_name");
  },
  group_id(state, n) {
    state.group_id = n;
    token.setCookie("group_id", n);
    if (!n) token.delCookie("group_id");
  },
  root_id(state, n) {
    state.root_id = n;
    token.setCookie("root_id", n);
    if (!n) token.delCookie("root_id");
  },
  qiniu(state, n) {
    state.qiniu = n;
    token.setCookie("qiniu", n);
    if (!n) token.delCookie("qiniu");
  },
  wx_appid(state, n) {
    state.wx_appid = n;
  },
  isshow(state, n) {
    state.isshow = n;
  },
  imgInitPgae(state, n) {
    state.imgInitPgae = n;
  },
  spellGroupIndex(state, n) {
    state.spellGroupIndex = n;
  },
  limitIndex(state, n) {
    state.limitIndex = n;
  },
  bargainIndex(state, n) {
    state.bargainIndex = n;
  }
};
export default new Vuex.Store({
  state,
  getters,
  mutations
});
